home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cgazv5n5.arc / LIST4.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  1KB  |  40 lines

  1. /*---------------------------------------- Listing 4 ------
  2.  * Another demonstartion of SIGFPE signal.
  3.  * See Listing 1 for copyright terms.
  4.  *-------------------------------------------------------*/
  5. #include <stdio.h>
  6. #include <signal.h>
  7. #include <float.h>
  8.  
  9. void FpeHandler ( int Signal, int SubCode );
  10. void main ( void );
  11.  
  12. void FpeHandler ( int Signal, int SubCode )
  13. {
  14.     _fpreset();
  15.     printf ( "Signal %d, SubCode %d was raised\n",
  16.               Signal, SubCode );
  17. }
  18.  
  19. void main ( void )
  20. {
  21.     void (*OldHandler) ( int Signal );
  22.     int i, j, k;
  23.     float Bill, Gates;
  24.  
  25.     /*---------------------------------------------------------
  26.      * This is a dummy assignment to link in floating-point
  27.      * handler, which is prerequisite for SIGFPE signal
  28.      * installation in MSC!
  29.      *-------------------------------------------------------*/
  30.  
  31.     Bill = Gates;
  32.  
  33.     OldHandler = signal ( SIGFPE, FpeHandler );
  34.     if ( OldHandler == SIG_ERR )
  35.          printf ( "signal failed\n" );
  36.  
  37.     j  = i;
  38.     j -= i;
  39.     i /= j;     /* This is where it goes wrong */
  40. }